package cn.tuling.servlets;

import cn.tuling.interceptors.TimeInterceptor;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.*;

@Configuration
//@EnableWebMvc
public class MyWebMvcAutoConfiguration implements WebMvcConfigurer {

    /*@Bean
    public HiddenHttpMethodFilter hiddenHttpMethodFilter() {
        // do some coding
        // ..
        return new HiddenHttpMethodFilter();
    }*/

    @Override
    public void configurePathMatch(PathMatchConfigurer configurer) {
        configurer.setUseTrailingSlashMatch(false);
    }

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(new TimeInterceptor())
                //  添加映射规则
                .addPathPatterns("/**")
                //  添加排除的路径
                .excludePathPatterns("/pages/**");
    }

    @Override
    public void addCorsMappings(CorsRegistry registry) {
        registry.addMapping("/api/**")
                .allowedOrigins("http://localhost:8081")
                .allowedMethods("GET", "POST", "PUT", "DELETE");
    }
}
